package com.topscomm.pm;

import com.topscomm.basic.exception.ServiceException;
import com.topscomm.mis.MisService;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.tap.TapEntity;
import com.topscomm.tap.TapService;
import com.topscomm.tap.common.SessionUserBean;

@SuppressWarnings("rawtypes")
public class PmService <T extends PmEntity, TDao extends IPmDao> extends MisService<T, TDao> implements IPmService<T, TDao> {

	/**
	 * 统一的给扩充字段赋值，第一个为单号，第二个为申请部门，第三个位申请人
	 */
	@Override
	protected void afterSubmit(TapEntity entity,SessionUserBean sessionUserBean) {
		try {
			StringBufferProxy sql = new StringBufferProxy();
			sql.appendLineSingle("update CboApprovalFlowIns set ");
			sql.appendLineSingle("extendfield1 = (select docno from {0} "
					+ "where CboApprovalFlowIns.sourceid = {0}.id "
					+ "and CboApprovalFlowIns.sourcetype = '{0}'),", entity.getTableName());
			sql.appendLineSingle("extendfield2 = (select deptcode from {0} "
					+ "where CboApprovalFlowIns.sourceid = {0}.id "
					+ "and CboApprovalFlowIns.sourcetype = '{0}'),", entity.getTableName());
			sql.appendLineSingle("extendfield3 = (select usercode from {0} "
					+ "where CboApprovalFlowIns.sourceid = {0}.id "
					+ "and CboApprovalFlowIns.sourcetype = '{0}')", entity.getTableName());
			sql.appendLineSingle("where sourceid = '{0}' and sourcetype='{1}'", entity.getId(),entity.getTableName());

			this.getDao().updateExecute(sql.toString());
			super.afterSubmit(entity,sessionUserBean);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}
}
